VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "classSettings"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Project Name:  Shared
' Host Name:     Shared.classSettings
' Date:          2005-12-22
' Version:       4.00
'
' Encapsulate an XML document to hold program settings and history.
'
' 2005-12-21, JFW, 4.00, New module.
' 2006-09-15, JFW, Copied from FCIL to FXI class.
'

Option Explicit

Dim xmlDoc As DOMDocument ' MSXML2.DOMDocument ' FSIX.Document
Dim mxmlProfile As IXMLDOMNode
'



Public Sub EditSettings()

    Dim objSheet As Worksheet
    Dim i As Long, j As Long
    Dim xmlNodeProfile As IXMLDOMNode
    Dim xmlNodeSetting As IXMLDOMNode
    
    If xmlDoc Is Nothing Then Me.OpenSettings
    
    With Workbooks.Add
        ' .Name = "FSMWebMacroConfig"
        If .Sheets.Count <= 0 Then
            Set objSheet = .Sheets.Add
        Else
            Set objSheet = .Sheets(1)
        End If
        With objSheet
            .Cells(1, 1) = "CurrentProfile"
            .Cells(1, 2) = xmlDoc.FirstChild.selectSingleNode("CurrentProfile").Text
            .Cells(2, 1) = "LastModified"
            .Cells(2, 2) = xmlDoc.FirstChild.selectSingleNode("LastModified").Text
            i = 1
            For Each xmlNodeProfile In xmlDoc.FirstChild.selectNodes("Profile")
                i = i + 1
                j = 3
                For Each xmlNodeSetting In xmlNodeProfile.childNodes
                    j = j + 1
                    .Cells(j, 1) = xmlNodeSetting.nodeName
                    .Cells(j, i) = "'" & xmlNodeSetting.Text
                Next xmlNodeSetting
            Next xmlNodeProfile
            .Columns.AutoFit
        
            ' Ensure current settings have all options
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("ProfileName") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "ProfileName"
                .Cells(j, 2) = "FirstProfile"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("ACCOUNT_NUMBER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "ACCOUNT_NUMBER"
                .Cells(j, 2) = "340763106"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("METER_NUMBER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "METER_NUMBER"
                .Cells(j, 2) = "123456789"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("API_ENVIRONMENT") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "API_ENVIRONMENT"
                .Cells(j, 2) = "production"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("WS_KEY") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "WS_KEY"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("WS_PASSWORD") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "WS_PASSWORD"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("PRINTER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "PRINTER"
                .Cells(j, 2) = "\\127.0.0.1\ZebraZP5"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("HEADER_ROW") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "HEADER_ROW"
                .Cells(j, 2) = "1"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_CONTACT") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_CONTACT"
                .Cells(j, 2) = "Sender Contact"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_COMPANY") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_COMPANY"
                .Cells(j, 2) = "FedEx Customer Technology"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_DEPARTMENT") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_DEPARTMENT"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_PHONE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_PHONE"
                .Cells(j, 2) = "9052125000"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_EMAIL") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_EMAIL"
                .Cells(j, 2) = "test@fedex.com"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_ADDR1") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_ADDR1"
                .Cells(j, 2) = "5985 Explorer Dr."
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_ADDR2") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_ADDR2"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_CITY") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_CITY"
                .Cells(j, 2) = "Mississauga"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_STPV") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_STPV"
                .Cells(j, 2) = "ON"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_ZIP") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_ZIP"
                .Cells(j, 2) = "L4W5K6"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SENDER_COUNTRY") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SENDER_COUNTRY"
                .Cells(j, 2) = "CA"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("LABEL_FOLDER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "LABEL_FOLDER"
                .Cells(j, 2) = g_objFSO.GetSpecialFolder(2) & "\"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("LOG_FOLDER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "LOG_FOLDER"
                .Cells(j, 2) = g_objFSO.GetSpecialFolder(2) & "\"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("MAIL_FOLDER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "MAIL_FOLDER"
                .Cells(j, 2) = "" ' "C:\Documents and Settings\All Users\Documents\MailDaemon\"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHIPPING_WEIGHT") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHIPPING_WEIGHT"
                .Cells(j, 2) = "1"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("WEIGHT_TYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "WEIGHT_TYPE"
                .Cells(j, 2) = "LB"  'or "KG"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_CONTACT") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_CONTACT"
                .Cells(j, 2) = "FullName"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_COMPANY") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_COMPANY"
                .Cells(j, 2) = "Company"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_DEPARTMENT") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_DEPARTMENT"
                .Cells(j, 2) = "Department"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_ADDRESS1") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_ADDRESS1"
                .Cells(j, 2) = "AddressOne"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_ADDRESS2") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_ADDRESS2"
                .Cells(j, 2) = "AddressTwo"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_CITY") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_CITY"
                .Cells(j, 2) = "City"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_STATE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_STATE"
                .Cells(j, 2) = "State"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_ZIP") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_ZIP"
                .Cells(j, 2) = "Zip"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_PHONE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_PHONE"
                .Cells(j, 2) = "PhoneNumber"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_COUNTRYCODE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_COUNTRYCODE"
                .Cells(j, 2) = "CountryCode"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_EMAIL") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_EMAIL"
                .Cells(j, 2) = "EmailAddress"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_TAXID") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_TAXID"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_REFERENCE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_REFERENCE"
                .Cells(j, 2) = "Reference"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_SERVICETYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_SERVICETYPE"
                .Cells(j, 2) = "ServiceType"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("DEFAULT_INTL_SERVICETYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "DEFAULT_INTL_SERVICETYPE"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("DEFAULT_DOM_SERVICETYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "DEFAULT_DOM_SERVICETYPE"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_PACKAGETYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_PACKAGETYPE"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_INVOICENUMBER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_INVOICENUMBER"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("SHEET_PONUMBER") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "SHEET_PONUMBER"
                .Cells(j, 2) = ""
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("LABEL_FORMAT_TYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "LABEL_FORMAT_TYPE"
                .Cells(j, 2) = "COMMON2D"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("RATE_TRANSIT_TIME") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "RATE_TRANSIT_TIME"
                .Cells(j, 2) = "True"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("RATE_DETAIL") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "RATE_DETAIL"
                .Cells(j, 2) = "True"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("LABEL_IMAGE_TYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "LABEL_IMAGE_TYPE"
                .Cells(j, 2) = "ZPL2"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("LABEL_STOCK_TYPE") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "LABEL_STOCK_TYPE"
                .Cells(j, 2) = "STOCK_4X6"
            End If
            If .Range(.Cells(3, 1), .Cells(j, 1)).Find("TrackingNumber") Is Nothing Then
                j = j + 1
                .Cells(j, 1) = "TrackingNumber"
                .Cells(j, 2) = "TrackingNumber"
            End If
        
        End With
    End With

End Sub

'---------------------------------------------------------------------------------------
' Procedure : OpenSettings
' DateTime  : 2005-12-22
' Purpose   : Open or create a settings document, located in Projects folder.
'---------------------------------------------------------------------------------------
Public Function OpenSettings(Optional strFilename As String = "") As Boolean

    On Error GoTo ErrorExit
    Dim xmlNode As IXMLDOMNode
    
    If g_objFSO Is Nothing Then Set g_objFSO = New FileSystemObject
    
    Set xmlDoc = New DOMDocument ' MSXML2.DOMDocument ' xml.CreateDocument("c:\" & Manifest.MasterShipment(1).MasterShipmentID & ".xml")
    
    ' Check for Win Vista
    If Right(g_objFSO.GetSpecialFolder(2), 10) = "Local\Temp" Then
        If Not g_objFSO.FolderExists(g_objFSO.GetSpecialFolder(2) & "\..\FedEx") Then
            g_objFSO.CreateFolder g_objFSO.GetSpecialFolder(2) & "\..\FedEx"
        End If
        If Not xmlDoc.Load(g_objFSO.GetSpecialFolder(2) & "\..\FedEx\FSMWebMacroConfig.xml") Then
            Set xmlDoc = Nothing
        End If
    ' Win XP
    ElseIf g_objFSO.FolderExists(g_objFSO.GetSpecialFolder(2) & "\..\..\Application Data") Then
        If Not g_objFSO.FolderExists(g_objFSO.GetSpecialFolder(2) & "\..\..\Application Data\FedEx") Then
            g_objFSO.CreateFolder g_objFSO.GetSpecialFolder(2) & "\..\..\Application Data\FedEx"
        End If
        If Not xmlDoc.Load(g_objFSO.GetSpecialFolder(2) & "\..\..\Application Data\FedEx\FSMWebMacroConfig.xml") Then
            Set xmlDoc = Nothing
        End If
    ' Cafe hardware on XP
    ElseIf g_objFSO.FolderExists("C:\Documents and Settings\Administrator\Application Data") Then
        If Not g_objFSO.FolderExists("C:\Documents and Settings\Administrator\Application Data\FedEx") Then
            g_objFSO.CreateFolder "C:\Documents and Settings\Administrator\Application Data\FedEx"
        End If
        If Not xmlDoc.Load("C:\Documents and Settings\Administrator\Application Data\FedEx\FSMWebMacroConfig.xml") Then
            Set xmlDoc = Nothing
        End If
    Else
        Err.Raise 12345, "Settings", "Cannot determine folder User Application Data."
    End If
    
    If xmlDoc Is Nothing Then
        Set xmlDoc = New DOMDocument
        With xmlDoc.appendChild(xmlDoc.createElement("FSMWebMacroConfig"))
            .appendChild(xmlDoc.createElement("LastModified")).Text = Format(Now, "yyyy-mm-dd HH:nn:ss")
            .appendChild(xmlDoc.createElement("CurrentProfile")).Text = "FirstProfile"
            With .appendChild(xmlDoc.createElement("Profile"))
                .appendChild(xmlDoc.createElement("ProfileName")).Text = "FirstProfile"
                .appendChild(xmlDoc.createElement("ACCOUNT_NUMBER")).Text = "340763106"
                .appendChild(xmlDoc.createElement("METER_NUMBER")).Text = "101712435"
                .appendChild(xmlDoc.createElement("API_ENVIRONMENT")).Text = "production"
                .appendChild(xmlDoc.createElement("WS_KEY")).Text = "Hul6CUbNTlXLZglv"
                .appendChild(xmlDoc.createElement("WS_PASSWORD")).Text = "m089kanA3TZElrkB019Hf1Jmi"
                .appendChild(xmlDoc.createElement("PRINTER")).Text = "" ' "\\127.0.0.1\ZebraZP5"
                .appendChild(xmlDoc.createElement("HEADER_ROW")).Text = "1"
                .appendChild(xmlDoc.createElement("SENDER_CONTACT")).Text = "Joseph Weir Test"
                .appendChild(xmlDoc.createElement("SENDER_COMPANY")).Text = "FedEx Customer Technology"
                .appendChild(xmlDoc.createElement("SENDER_DEPARTMENT")).Text = ""
                .appendChild(xmlDoc.createElement("SENDER_PHONE")).Text = "9052125000"
                .appendChild(xmlDoc.createElement("SENDER_EMAIL")).Text = "joseph.weir@fedex.com"
                .appendChild(xmlDoc.createElement("SENDER_ADDR1")).Text = "5985 Explorer Dr."
                .appendChild(xmlDoc.createElement("SENDER_ADDR2")).Text = ""
                .appendChild(xmlDoc.createElement("SENDER_CITY")).Text = "Mississauga"
                .appendChild(xmlDoc.createElement("SENDER_STPV")).Text = "ON"
                .appendChild(xmlDoc.createElement("SENDER_ZIP")).Text = "L4W5K6"
                .appendChild(xmlDoc.createElement("SENDER_COUNTRY")).Text = "CA"
                .appendChild(xmlDoc.createElement("LABEL_FOLDER")).Text = g_objFSO.GetSpecialFolder(2) & "\"
                .appendChild(xmlDoc.createElement("LOG_FOLDER")).Text = g_objFSO.GetSpecialFolder(2) & "\"
                .appendChild(xmlDoc.createElement("MAIL_FOLDER")).Text = "" ' "C:\Documents and Settings\All Users\Documents\MailDaemon\"

                .appendChild(xmlDoc.createElement("SHIPPING_WEIGHT")).Text = "1"
                .appendChild(xmlDoc.createElement("WEIGHT_TYPE")).Text = "LB"  'or "KG"
                .appendChild(xmlDoc.createElement("SHEET_CONTACT")).Text = "FullName"
                .appendChild(xmlDoc.createElement("SHEET_COMPANY")).Text = "Company"
                .appendChild(xmlDoc.createElement("SHEET_DEPARTMENT")).Text = "Department"
                .appendChild(xmlDoc.createElement("SHEET_ADDRESS1")).Text = "AddressOne"
                .appendChild(xmlDoc.createElement("SHEET_ADDRESS2")).Text = "AddressTwo"
                .appendChild(xmlDoc.createElement("SHEET_CITY")).Text = "City"
                .appendChild(xmlDoc.createElement("SHEET_STATE")).Text = "State"
                .appendChild(xmlDoc.createElement("SHEET_ZIP")).Text = "Zip"
                .appendChild(xmlDoc.createElement("SHEET_PHONE")).Text = "PhoneNumber"
                .appendChild(xmlDoc.createElement("SHEET_COUNTRYCODE")).Text = "CountryCode"
                .appendChild(xmlDoc.createElement("SHEET_EMAIL")).Text = "EmailAddress"
                .appendChild(xmlDoc.createElement("SHEET_TAXID")).Text = "CustomsIDEIN"
                .appendChild(xmlDoc.createElement("SHEET_REFERENCE")).Text = "Reference"
                .appendChild(xmlDoc.createElement("SHEET_SERVICETYPE")).Text = "ServiceType"
                .appendChild(xmlDoc.createElement("DEFAULT_INTL_SERVICETYPE")).Text = ""
                .appendChild(xmlDoc.createElement("DEFAULT_DOM_SERVICETYPE")).Text = ""
                .appendChild(xmlDoc.createElement("SHEET_PACKAGETYPE")).Text = "PackageType"
                .appendChild(xmlDoc.createElement("SHEET_INVOICENUMBER")).Text = "INVOICENUMBER"
                .appendChild(xmlDoc.createElement("SHEET_PONUMBER")).Text = "PONUMBER"
            
                .appendChild(xmlDoc.createElement("LABEL_FORMAT_TYPE")).Text = "COMMON2D"
                .appendChild(xmlDoc.createElement("RATE_TRANSIT_TIME")).Text = "True"
                .appendChild(xmlDoc.createElement("RATE_DETAIL")).Text = "True"
                .appendChild(xmlDoc.createElement("LABEL_IMAGE_TYPE")).Text = "ZPL2"
                .appendChild(xmlDoc.createElement("LABEL_STOCK_TYPE")).Text = "STOCK_4X6"
            
                .appendChild(xmlDoc.createElement("TrackingNumber")).Text = "TrackingNumber"
            End With
        End With
    End If

    For Each mxmlProfile In xmlDoc.FirstChild.selectNodes("Profile")
        If mxmlProfile.selectSingleNode("ProfileName").Text = xmlDoc.FirstChild.selectSingleNode("CurrentProfile").Text Then
            Exit For
        End If
    Next mxmlProfile

    Exit Function
    
ErrorExit:
    Err.Raise 12345, "Settings.OpenSettings", Err.Source & " - " & Err.Description

End Function
'


'---------------------------------------------------------------------------------------
' Procedure : SaveSettings
' DateTime  : 2005-12-22
' Purpose   : Call this after making any changes.
'---------------------------------------------------------------------------------------
Public Sub SaveSettings()
    
    On Error GoTo ErrorExit
    
    Dim objWookbook As Workbook
    Dim objSheet As Worksheet
    Dim i As Long, j As Long
    Dim xmlNodeProfile As IXMLDOMNode
    Dim xmlNodeSetting As IXMLDOMNode
    
    If xmlDoc Is Nothing Then Me.OpenSettings
    
    For Each objWookbook In Workbooks
        If objWookbook.Sheets(1).Cells(1, 1) = "CurrentProfile" Then
            Set xmlDoc = New DOMDocument
            With xmlDoc
                With .appendChild(xmlDoc.createElement("FSMWebMacroConfig"))
                    .appendChild(xmlDoc.createElement("CurrentProfile")).Text = objWookbook.Sheets(1).Cells(1, 2)
                    .appendChild(xmlDoc.createElement("LastModified")).Text = Format(Now, "yyyy-mm-dd HH:nn:ss")
                    For i = 2 To 999
                        If objWookbook.Sheets(1).Cells(4, i) <> "" Then
                            With .appendChild(xmlDoc.createElement("Profile"))
                                j = 3
                                Do
                                    j = j + 1
                                    If objWookbook.Sheets(1).Cells(j, 1) = "" Then Exit Do
                                    .appendChild(xmlDoc.createElement(objWookbook.Sheets(1).Cells(j, 1))).Text = objWookbook.Sheets(1).Cells(j, i)
                                Loop
                            End With
                        End If
                    Next i
                End With
            End With
        End If
    Next objWookbook

    For Each mxmlProfile In xmlDoc.FirstChild.selectNodes("Profile")
        If mxmlProfile.selectSingleNode("ProfileName").Text = xmlDoc.FirstChild.selectSingleNode("CurrentProfile").Text Then
            Exit For
        End If
    Next mxmlProfile

    ' Check Win Vista
    If Right(g_objFSO.GetSpecialFolder(2), 10) = "Local\Temp" Then
        xmlDoc.Save (g_objFSO.GetSpecialFolder(2) & "\..\FedEx\FSMWebMacroConfig.xml")
    ' Win XP
    ElseIf g_objFSO.FolderExists(g_objFSO.GetSpecialFolder(2) & "\..\..\Application Data\FedEx") Then
        xmlDoc.Save (g_objFSO.GetSpecialFolder(2) & "\..\..\Application Data\FedEx\FSMWebMacroConfig.xml")
    ' Cafe hardware on XP
    Else
        xmlDoc.Save ("C:\Documents and Settings\Administrator\Application Data\FedEx\FSMWebMacroConfig.xml")
    End If

    ' Debug.Print Now, "SaveSettings", "done", "Profile: " & Left(mxmlProfile.XML, 100)
    
    Exit Sub
    
ErrorExit:
    Err.Raise 12345, "Settings.SaveSettings", Err.Source & " - " & Err.Description

End Sub
    
    


'---------------------------------------------------------------------------------------
' Procedure : HistoryKey
' DateTime  : 2005-12-22
' Purpose   : Set and get the current history key.
'---------------------------------------------------------------------------------------
Public Property Get ProfileKey() As String
    If xmlDoc Is Nothing Then Me.OpenSettings
    If Not mxmlProfile Is Nothing Then
        ProfileKey = mxmlProfile.selectSingleNode("ProfileName").Text
    End If
End Property

Public Property Let ProfileKey(strNewValue As String)
    Dim xmlProfile As IXMLDOMNode
    If xmlDoc Is Nothing Then Me.OpenSettings
    For Each xmlProfile In xmlDoc.FirstChild.selectNodes("Profile")
        If xmlProfile.selectSingleNode("ProfileName").Text = strNewValue Then
            For Each mxmlProfile In xmlDoc.FirstChild.selectNodes("Profile")
                If mxmlProfile.selectSingleNode("ProfileName").Text = strNewValue Then
                    xmlDoc.FirstChild.selectSingleNode("CurrentProfile").Text = strNewValue
                    Call SaveSettings
                    Exit For
                End If
            Next mxmlProfile
        End If
    Next xmlProfile
End Property


'---------------------------------------------------------------------------------------
' Procedure : Setting
' DateTime  : 2005-12-22
' Purpose   : Get the value of a setting.
'---------------------------------------------------------------------------------------
Public Property Get Setting(strKeyName As String) As Variant
    On Error GoTo EmptySetting
    If xmlDoc Is Nothing Then Me.OpenSettings
    If Not mxmlProfile Is Nothing Then
        If mxmlProfile.selectSingleNode(strKeyName) Is Nothing Then
            mxmlProfile.appendChild xmlDoc.createElement(strKeyName)
            If strKeyName = "SHEET_SHIPDATE" Then
                mxmlProfile.selectSingleNode(strKeyName).Text = "ShipDate"
            End If
            If strKeyName = "TrackingNumber" Then
                mxmlProfile.selectSingleNode(strKeyName).Text = "TrackingNumber"
            End If
            SaveSettings
        End If
        Setting = mxmlProfile.selectSingleNode(strKeyName).Text
        Else
    End If
    Exit Property

EmptySetting:
    Err.Raise 12345, "Settings.Setting", Err.Source & " - " & Err.Description

End Property
'

'---------------------------------------------------------------------------------------
' Procedure : Setting
' DateTime  : 2005-12-22
' Purpose   : Set the value of a setting.
'---------------------------------------------------------------------------------------
Public Property Let Setting(strKeyName As String, varValue As Variant)
    On Error GoTo EmptySetting
    Dim xmlNode As IXMLDOMNode
    If xmlDoc Is Nothing Then Me.OpenSettings
    If Not mxmlProfile Is Nothing Then
        If mxmlProfile.selectSingleNode(strKeyName) Is Nothing Then
            mxmlProfile.appendChild xmlDoc.createElement(strKeyName)
        End If
        mxmlProfile.selectSingleNode(strKeyName).Text = varValue
    End If
    xmlDoc.FirstChild.selectSingleNode("LastModified").Text = Format(Now, "yyyy-mm-dd HH:mm:ss")
    Exit Property

EmptySetting:
    Err.Raise 12345, "Settings.Setting", Err.Source & " - " & Err.Description
    
End Property
'

'---------------------------------------------------------------------------------------
' Procedure : SettingWithDefault
' DateTime  : 2005-12-22
' Purpose   : Get the value of a setting and given a default.  Booleans only right now.
'---------------------------------------------------------------------------------------
Public Function SettingWithDefault(strSettingName As String, varDefaultValue As Variant) As Variant

    Err.Clear
    On Error Resume Next
    If xmlDoc Is Nothing Then Me.OpenSettings
    
    ' If Setting is blank then assume true
    If Me.Setting(strSettingName) = "" Then
        If Err.Number = 0 Then
            Me.Setting(strSettingName) = varDefaultValue
            Me.SaveSettings
        End If
    End If
    
    SettingWithDefault = Me.Setting(strSettingName)
    ' Any problems with the setting, then assume true
    If Err.Number <> 0 Then
        Err.Clear
        Me.Setting(strSettingName) = varDefaultValue
        Me.SaveSettings
        SettingWithDefault = varDefaultValue
    End If

End Function

